let express = require('express');
let multer = require('multer');
let fs = require("fs");
const cors = require('cors')
const app = express()

const MAO = require('multer-aliyun-oss');
app.use(cors());



app.get('/upload', function (req, res) {
   res.send("11")
})

app.post('/upload', multer({
   //设置文件存储路径
   // dest: "upload"
   storage: MAO({
      config: {
         region: 'oss-cn-guangzhou',
         accessKeyId: '填写你自己的',
         accessKeySecret: '填写你自己的',
         bucket: '填写你自己的',
      },
   })

}).array('file', 500), function (req, res, next) {  //这里10表示最大支持的文件上传数目
   let files = req.files;
   fileInfos = [];
   if (files.length === 0) {
      res.render("error", { message: "上传文件不能为空！" });
      return
   } else {
      res.send(files);
   }
});

app.use(express.static("upload"));

app.listen(3000, () => {
   console.log("启动成功  3000端口")
});